﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Reflection;
using System.ComponentModel;


namespace Catsland.Core
{
    public class CatComponent
    {
		private bool m_enable = true;
        [CategoryAttribute("Basic")]
        public bool Enable
        {
            set { m_enable = value; }
            get { return m_enable; }
        }

        public GameObject m_gameObject;

        public CatComponent(GameObject gameObject)
        {
            m_gameObject = gameObject;
        }

        public static CatComponent LoadFromNode(XmlElement node, Scene scene, GameObject gameObject)
        {
            string component_type = node.Name;
            Type type = Mgr<TypeManager>.Singleton.GetCatComponentType(component_type);
            if (type != null)
            {
                ConstructorInfo constructorInfo = type.GetConstructor(new Type[1] { typeof(GameObject) });
                CatComponent component = (CatComponent)constructorInfo.Invoke(new Object[1] { gameObject });
                component.ConfigureFromNode(node, scene, gameObject);
                return component;
            }
            return null;
        }

        public virtual void Initialize(Scene scene)
        {
        }

		public virtual void Update(int timeLastFrame)
        {

        }

        public virtual void EditorUpdate(int timeLastFrame)
        {

        }

		public virtual void BindToScene(Scene scene)
		{

		}

		public virtual CatComponent CloneComponent(GameObject gameObject)
		{
			return new CatComponent(gameObject);
		}

		public virtual bool SaveToNode(XmlNode node, XmlDocument doc)
		{
			return true;
		}

        public virtual void ConfigureFromNode(XmlElement node, Scene scene, GameObject gameObject)
        {

        }

		public virtual void Destroy()
		{

		}

        public virtual CatsModel GetModel()
        {
            return null;
        }
	}
}
